Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugins/classlib: Support multiple RandIDs in one SynthDef #6159

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

jamshark70
Copy link
Contributor

Purpose and Motivation

See https://scsynth.org/t/different-randseed-for-the-same-synthdef/7248/27, where it was desired to use more than one RNG ID in the same SynthDef. Prior to this change, this was impossible because RandID would set the ID only when the ID input changed. This use case requires setting the ID on every control block, once for one part of the graph, and again for the other part.

However, losing the old behavior would also not be desirable.

So this change adds a new input to RandID, force.

  • If force <= 0 (false), RandID behaves the old way, looking for changes in the input.
  • If force > 0 (true), RandID will set the ID in every control block, whether it changed or not.

The default is the old way.

As with a couple of other recent PRs, I would prefer not to have to write a unit test until we are reasonably sure this will be merged. So a unit test isn't yet provided. The approach would be to generate two separate, identically-seeded random number streams and make sure they are the same.

Types of changes

  • Documentation
  • New feature
  • Breaking change -- minimal impact I think(?)

To-do list

  • Code is tested (informally -- unit test to be written later)
  • All tests are passing
  • Updated documentation
  • This PR is ready for review

Copy link
Member

@telephon telephon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@jamshark70
Copy link
Contributor Author

Thanks @telephon for approving -- I just added two unit tests:

  • Seems we didn't have one for RandSeed before.
  • And a second test for the specific new feature in the PR.

@Sciss
Copy link
Contributor

Sciss commented Dec 26, 2023

Urgent reminder of #2363 - adding UGen arguments on the server side breaks the binary API and potentially crashes clients and earlier written SynthDefs (accessing unallocated memory). I'd appreciate if this issue was always strongly on the mind when considering editing UGens. We currently don't have a safe way to handle this.

Also, an API change marker should be added to these commits should they be merged.

@@ -790,9 +790,13 @@ void RandID_Ctor(RandID* unit) {

void RandID_next(RandID* unit, int inNumSamples) {
float id = ZIN0(0);
bool fire = ZIN0(1) > 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way we can know the number of allocated UGen inputs, so we could write

bool fire = num_ugen_args >= 2 && ZIN0(1) > 0

Then we would avoid crashing against clients and synth-defs using the previous ABI.

Copy link
Contributor

@Sciss Sciss Dec 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Christof noted that there is already a numInputs that could/should be used here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this?

    bool fire = (unit->mNumInputs >= 2 ? ZIN0(1) : 0.f) > 0.f;

Copy link
Contributor

@Sciss Sciss Jan 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it not just be

bool fire = unit->mNumInputs >= 2 && (ZIN0(1) > 0.f);

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool fire = unit->mNumInputs >= 2 && (ZIN0(1) > 0.f);

OK, done, passes an inputs-mismatch test.

@jamshark70
Copy link
Contributor Author

Agreed with sciss that these changes should be un-approved until the problem is resolved.

@jamshark70
Copy link
Contributor Author

adding UGen arguments on the server side breaks the binary API and potentially crashes clients and earlier written SynthDefs (accessing unallocated memory)

In this case, I could not reproduce a crash.

It's correct that we should keep this in mind (and my fault that I didn't think of it). It would also be good to understand the boundary conditions better (e.g., maybe adding a kr input is fine but adding an ar is not fine).

@telephon telephon self-requested a review February 26, 2024 13:29
Copy link
Member

@telephon telephon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

James requested an un-approve until the issue is solved. Thank you – done here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants